﻿using System.Linq;
using System.Web.Mvc;
using MemcachedProviders.Cache;
using ProjectYANApi.MemcachedFunction;
using ProjectYANApi.Models;
using YanOnline.Function;
using System.Collections.Generic;
using ProjectYANApi.Function;

namespace ProjectYANApi.Controllers
{
    public class apiController : Controller
    {
        dbYanOnlineDataContext db = new dbYanOnlineDataContext();

        public ActionResult ClearCache()
        {
            return View();
        }

        [HttpPost]
        public ActionResult ClearCache(string type)
        {
            DistCache.RemoveAll();
            ViewData["MessageClearCache"] = "Done!";
            return RedirectToAction("ClearCache", "api");
        }


        public ActionResult Index()
        {
            return View();
        }

        //[CompressFilter]
        //public JsonResult GetListCategory()
        //{
        //    JsonResult result = new JsonResult();
        //    result.JsonRequestBehavior = JsonRequestBehavior.AllowGet;

        //    object obj = DistCache.Get(MemcachedKey.hsGetListCategory);
        //    if (obj == null)
        //    {
        //        var lst = from p in db.tblCategories
        //                  where p.ZoneId == 4
        //                  select new { p.Id, Title = p.CategoryName };
        //        object data = null;
        //        data = new { result = true, ListData = lst };
        //        result.Data = data;
        //        DistCache.Add(MemcachedKey.hsGetListCategory, data);
        //    }
        //    else
        //    {
        //        result.Data = obj;
        //    }
        //    return result;
        //}

        [CompressFilter]
        public JsonResult tblContentGetHomePage(int PageSize, int pageNumber)
        {
            JsonResult result = new JsonResult();
            result.JsonRequestBehavior = JsonRequestBehavior.AllowGet;
            List<ListContent> lst = new List<ListContent>();
            object obj = DistCache.Get(MemcachedKey.hstblContentGetHomePage + "_" + pageNumber);
            if (obj == null)
            {
                lst = clsFunction.Api_tblContentGetHomePage(30, pageNumber);
                DistCache.Add(MemcachedKey.hstblContentGetHomePage + "_" + pageNumber, lst);
            }
            else
            {
                lst = (List<ListContent>)obj;
            }

            object data = null;
            var lstTmp = lst.ToList();

            if (lstTmp.Count > 0)
                data = new { result = true, ListData = lstTmp };
            else
                data = new { result = false };
            result.Data = data;
            return result;
        }

        public JsonResult tblContentGetHomePageNew(int PageSize, int pageNumber)
        {
            JsonResult result = new JsonResult();
            result.JsonRequestBehavior = JsonRequestBehavior.AllowGet;
            List<ListContent> lst = new List<ListContent>();
            object obj = DistCache.Get(MemcachedKey.hstblContentGetHomePage + "_" + pageNumber);
            if (obj == null)
            {
                lst = clsFunction.Api_tblContentGetHomePage(30, pageNumber);
                DistCache.Add(MemcachedKey.hstblContentGetHomePage + "_" + pageNumber, lst);
            }
            else
            {
                lst = (List<ListContent>)obj;
            }

            object data = null;
            var lstTmp = lst.ToList();

            if (lstTmp.Count > 0)
                data = new { result = true, ListData = lstTmp };
            else
                data = new { result = false };
            result.Data = data;
            return result;
        }

        //public JsonResult SearchKeyword(string strText, int? intStart, int? intOffset)
        //{
        //    JsonResult result = new JsonResult();
        //    result.JsonRequestBehavior = JsonRequestBehavior.AllowGet;

        //    if (intStart == null)
        //        intStart = 1;

        //    if (intOffset == null)
        //        intOffset = 10;

        //    int intCount = 0;
        //    var lst = from p in dbFunction.SearchKeyword(strText, intStart.Value, intOffset.Value, ref  intCount)
        //              select new { p.Id, p.Title, p.Avatar, p.Teaser, p.UrlLink };

        //    object data = null;
        //    var lstTmp = lst.ToList();

        //    if (lstTmp.Count > 0)
        //        data = new { result = true, ListData = lstTmp, Total = intCount };
        //    else
        //        data = new { result = false };

        //    result.Data = data;

        //    return result;
        //}

        [CompressFilter]
        public JsonResult tblContentGetBlogZoneWithPage(int PageSize, int pageNumber)
        {
            JsonResult result = new JsonResult();
            result.JsonRequestBehavior = JsonRequestBehavior.AllowGet;
            List<ListContent> lst = new List<ListContent>();
            object obj = DistCache.Get(MemcachedKey.hstblContentGetBlogZoneWithPage + "_" + pageNumber);
            if (obj == null)
            {
                lst = clsFunction.Api_tblContentGetBlogZoneWithPage(30, pageNumber);
                DistCache.Add(MemcachedKey.hstblContentGetBlogZoneWithPage + "_" + pageNumber, lst);
            }
            else
            {
                lst = (List<ListContent>)obj;
            }
            object data = null;
            var lstTmp = lst.ToList();

            if (lstTmp.Count > 0)
                data = new { result = true, ListData = lstTmp };
            else
                data = new { result = false };
            result.Data = data;
            return result;
        }

        [CompressFilter]
        public JsonResult tblContentGetCelebZoneWithPage(int PageSize, int pageNumber)
        {
            JsonResult result = new JsonResult();
            result.JsonRequestBehavior = JsonRequestBehavior.AllowGet;
            List<ListContent> lst = new List<ListContent>();
            object obj = DistCache.Get(MemcachedKey.hstblContentGetCelebZoneWithPage + "_" + pageNumber);
            if (obj == null)
            {
                lst = clsFunction.Api_tblContentGetCelebZoneWithPage(30, pageNumber);
                DistCache.Add(MemcachedKey.hstblContentGetCelebZoneWithPage + "_" + pageNumber, lst);
            }
            else
            {
                lst = (List<ListContent>)obj;
            }

            object data = null;
            var lstTmp = lst.ToList();

            if (lstTmp.Count > 0)
                data = new { result = true, ListData = lstTmp };
            else
                data = new { result = false };
            result.Data = data;
            return result;
        }

        [CompressFilter]
        public JsonResult Api_tblContentGetByZoneWithPage(int PageSize, int pageNumber, int zoneId)
        {
            JsonResult result = new JsonResult();
            result.JsonRequestBehavior = JsonRequestBehavior.AllowGet;
            List<ListContent> lst = new List<ListContent>();
            object obj = DistCache.Get(MemcachedKey.hsApi_tblContentGetByZoneWithPage + "_" + pageNumber + "_" + zoneId);
            if (obj == null)
            {
                lst = clsFunction.Api_tblContentGetByZoneWithPage(PageSize, pageNumber, zoneId);
                DistCache.Add(MemcachedKey.hsApi_tblContentGetByZoneWithPage + "_" + pageNumber + "_" + zoneId, lst);
            }
            else
            {
                lst = (List<ListContent>)obj;
            }

            object data = null;
            var lstTmp = lst.ToList();

            if (lstTmp.Count > 0)
                data = new { result = true, ListData = lstTmp };
            else
                data = new { result = false };
            result.Data = data;
            return result;
        }


        [CompressFilter]
        public JsonResult GetDataForComicCon()
        {
            JsonResult result = new JsonResult();
            result.JsonRequestBehavior = JsonRequestBehavior.AllowGet;
            List<tblNews> lst = new List<tblNews>();
            object obj = DistCache.Get(MemcachedKey.hsGetForPartner);
            if (obj == null)
            {
                lst = clsFunction.tblContentNewsSearchTagGetAll("comic con");
                DistCache.Add(MemcachedKey.hsGetForPartner, lst);
            }
            else
            {
                lst = (List<tblNews>)obj;
            }

            object data = null;
            var lstTmp = lst.ToList();

            if (lstTmp.Count > 0)
                data = new { result = true, ListData = lstTmp };
            else
                data = new { result = false };
            result.Data = data;
            return result;
        }

        [CompressFilter]
        public JsonResult tblContentGetVideoZoneWithPage(int PageSize, int pageNumber)
        {
            JsonResult result = new JsonResult();
            result.JsonRequestBehavior = JsonRequestBehavior.AllowGet;
            List<ListContent> lst = new List<ListContent>();
            object obj = DistCache.Get(MemcachedKey.hstblContentGetVideoZoneWithPage + "_" + pageNumber);
            if (obj == null)
            {
                lst = clsFunction.Api_tblContentGetVideoZoneWithPage(30, pageNumber);
                DistCache.Add(MemcachedKey.hstblContentGetVideoZoneWithPage + "_" + pageNumber, lst);
            }
            else
            {
                lst = (List<ListContent>)obj;
            }

            object data = null;
            var lstTmp = lst.ToList();

            if (lstTmp.Count > 0)
                data = new { result = true, ListData = lstTmp };
            else
                data = new { result = false };
            result.Data = data;
            return result;
        }

        [CompressFilter]
        public JsonResult tblContentGetEnterZoneWithPage(int PageSize, int pageNumber)
        {
            JsonResult result = new JsonResult();
            result.JsonRequestBehavior = JsonRequestBehavior.AllowGet;

            List<ListContent> lst = new List<ListContent>();
            object obj = DistCache.Get(MemcachedKey.hstblContentGetEnterZoneWithPage + "_" + pageNumber);
            if (obj == null)
            {
                lst = clsFunction.Api_tblContentGetEnterZoneWithPage(30, pageNumber);
                DistCache.Add(MemcachedKey.hstblContentGetEnterZoneWithPage + "_" + pageNumber, lst);
            }
            else
            {
                lst = (List<ListContent>)obj;
            }

            object data = null;
            var lstTmp = lst.ToList();

            if (lstTmp.Count > 0)
                data = new { result = true, ListData = lstTmp };
            else
                data = new { result = false };
            result.Data = data;
            return result;
        }

        [CompressFilter]
        public JsonResult tblContentGetFeaturedWithPage(int PageSize, int pageNumber)
        {
            JsonResult result = new JsonResult();
            result.JsonRequestBehavior = JsonRequestBehavior.AllowGet;

            List<ListContent> lst = new List<ListContent>();
            object obj = DistCache.Get(MemcachedKey.hstblContentGetFeaturedWithPage + "_" + pageNumber);
            if (obj == null)
            {
                lst = clsFunction.Api_tblContentGetFeaturedWithPage(30, pageNumber);
                DistCache.Add(MemcachedKey.hstblContentGetFeaturedWithPage + "_" + pageNumber, lst);
            }
            else
            {
                lst = (List<ListContent>)obj;
            }

            object data = null;
            var lstTmp = lst.ToList();

            if (lstTmp.Count > 0)
                data = new { result = true, ListData = lstTmp };
            else
                data = new { result = false };
            result.Data = data;
            return result;
        }

        [CompressFilter]
        public JsonResult tblContentGetNewNewsWithPage(int PageSize, int pageNumber)
        {
            JsonResult result = new JsonResult();
            result.JsonRequestBehavior = JsonRequestBehavior.AllowGet;

            List<ListContent> lst = new List<ListContent>();
            object obj = DistCache.Get(MemcachedKey.hstblContentGetNewNewsWithPage + "_" + pageNumber);
            if (obj == null)
            {
                lst = clsFunction.Api_tblContentGetNewNewsWithPage(30, pageNumber);
                DistCache.Add(MemcachedKey.hstblContentGetNewNewsWithPage + "_" + pageNumber, lst);
            }
            else
            {
                lst = (List<ListContent>)obj;
            }

            object data = null;
            var lstTmp = lst.ToList();

            if (lstTmp.Count > 0)
                data = new { result = true, ListData = lstTmp };
            else
                data = new { result = false };
            result.Data = data;
            return result;
        }

        [CompressFilter]
        public JsonResult tblContentGetFeatured()
        {
            JsonResult result = new JsonResult();
            result.JsonRequestBehavior = JsonRequestBehavior.AllowGet;

            List<ListContent> lst = new List<ListContent>();
            object obj = DistCache.Get(MemcachedKey.hstblContentGetFeatured);
            if (obj == null)
            {
                lst = clsFunction.Api_tblContentGetFeatured();
                DistCache.Add(MemcachedKey.hstblContentGetFeatured, lst);
            }
            else
            {
                lst = (List<ListContent>)obj;
            }

            object data = null;
            var lstTmp = lst.ToList();

            if (lstTmp.Count > 0)
                data = new { result = true, ListData = lstTmp };
            else
                data = new { result = false };
            result.Data = data;
            return result;
        }

        [CompressFilter]
        public JsonResult ContentGetFeaturedByZone(int ZoneId, int Num)
        {
            JsonResult result = new JsonResult();
            result.JsonRequestBehavior = JsonRequestBehavior.AllowGet;

            List<ListContent> lst = new List<ListContent>();
            object obj = DistCache.Get(MemcachedKey.hstblContentGetFeaturedByZone + ZoneId + "_" + Num);
            if (obj == null)
            {
                lst = clsFunction.Api_tblContentGetFeaturedByZone(ZoneId, Num);
                DistCache.Add(MemcachedKey.hstblContentGetFeaturedByZone + ZoneId + "_" + Num, lst);
            }
            else
            {
                lst = (List<ListContent>)obj;
            }

            object data = null;
            var lstTmp = lst.ToList();

            if (lstTmp.Count > 0)
                data = new { result = true, ListData = lstTmp };
            else
                data = new { result = false };
            result.Data = data;
            return result;
        }

        [CompressFilter]
        public JsonResult ContentGetMostRead(int ZoneId, int Num)
        {
            JsonResult result = new JsonResult();
            result.JsonRequestBehavior = JsonRequestBehavior.AllowGet;

            List<ListContent> lst = new List<ListContent>();
            object obj = DistCache.Get(MemcachedKey.hstblContentGetMostRead + ZoneId + "_" + Num);
            if (obj == null)
            {
                lst = clsFunction.Api_tblContentGetMostRead(ZoneId, Num);
                DistCache.Add(MemcachedKey.hstblContentGetMostRead + ZoneId + "_" + Num, lst);
            }
            else
            {
                lst = (List<ListContent>)obj;
            }

            object data = null;
            var lstTmp = lst.ToList();

            if (lstTmp.Count > 0)
                data = new { result = true, ListData = lstTmp };
            else
                data = new { result = false };
            result.Data = data;
            return result;
        }

        //[CompressFilter]
        //public JsonResult tblContentGetRelated(string pText, int pId, int PageSize)
        //{
        //    string lOld = "src=\"//www.youtube.com";
        //    string lNew = "src=\"http://www.youtube.com";

        //    JsonResult result = new JsonResult();
        //    result.JsonRequestBehavior = JsonRequestBehavior.AllowGet;

        //    var lst = from p in db.Api_tblContentGetRelated(pText, pId, PageSize)
        //              select new { p.Id, p.Title, p.ViewCount, Body = p.Boby.Replace(lOld, lNew).Replace("src=\"/embed", "title=\"/embed"), DistributionDate = ConvertUtility.ToDateTime(p.DistributionDate).ToString("dd/MM/yyyy HH:mm"), p.Source, strLink = "http://yan.vn/" + StringUtility.UnicodeToKoDau(p.Title) + "-" + p.Id + ".html" };
        //    object data = null;
        //    var lstTmp = lst.ToList();

        //    if (lstTmp.Count > 0)
        //        data = new { result = true, ListData = lstTmp };
        //    else
        //        data = new { result = false };
        //    result.Data = data;
        //    return result;
        //}

        //[CompressFilter]
        //public JsonResult tblContentGetNewNews()
        //{
        //    JsonResult result = new JsonResult();
        //    result.JsonRequestBehavior = JsonRequestBehavior.AllowGet;

        //    var lst = from p in db.Api_tblContentGetNewNews()
        //              select new { p.Id, p.ZoneId, p.Title, p.ViewCount, DistributionDate = ConvertUtility.ToDateTime(p.DistributionDate).ToString("dd/MM/yyyy HH:mm"), p.Avatar };
        //    object data = null;
        //    var lstTmp = lst.ToList();

        //    if (lstTmp.Count > 0)
        //        data = new { result = true, ListData = lstTmp };
        //    else
        //        data = new { result = false };
        //    result.Data = data;
        //    return result;
        //}

        //[CompressFilter]
        //public JsonResult tblContentGetCelebZone()
        //{
        //    JsonResult result = new JsonResult();
        //    result.JsonRequestBehavior = JsonRequestBehavior.AllowGet;

        //    var lst = from p in db.Api_tblContentGetCelebZone()
        //              select new { p.Id, p.ZoneId, p.Title, p.ViewCount, DistributionDate = ConvertUtility.ToDateTime(p.DistributionDate).ToString("dd/MM/yyyy HH:mm"), p.Avatar };
        //    object data = null;
        //    var lstTmp = lst.ToList();

        //    if (lstTmp.Count > 0)
        //        data = new { result = true, ListData = lstTmp };
        //    else
        //        data = new { result = false };
        //    result.Data = data;
        //    return result;
        //}

        //[CompressFilter]
        //public JsonResult tblContentGetVideoZone()
        //{
        //    JsonResult result = new JsonResult();
        //    result.JsonRequestBehavior = JsonRequestBehavior.AllowGet;

        //    var lst = from p in db.Api_tblContentGetVideoZone()
        //              select new { p.Id, p.ZoneId, p.Title, p.ViewCount, DistributionDate = ConvertUtility.ToDateTime(p.DistributionDate).ToString("dd/MM/yyyy HH:mm"), p.Avatar };
        //    object data = null;
        //    var lstTmp = lst.ToList();

        //    if (lstTmp.Count > 0)
        //        data = new { result = true, ListData = lstTmp };
        //    else
        //        data = new { result = false };
        //    result.Data = data;
        //    return result;
        //}

        //[CompressFilter]
        //public JsonResult tblContentGetEnterZone()
        //{
        //    JsonResult result = new JsonResult();
        //    result.JsonRequestBehavior = JsonRequestBehavior.AllowGet;

        //    var lst = from p in db.Api_tblContentGetEnterZone()
        //              select new { p.Id, p.ZoneId, p.Title, p.ViewCount, DistributionDate = ConvertUtility.ToDateTime(p.DistributionDate).ToString("dd/MM/yyyy HH:mm"), p.Avatar };
        //    object data = null;
        //    var lstTmp = lst.ToList();

        //    if (lstTmp.Count > 0)
        //        data = new { result = true, ListData = lstTmp };
        //    else
        //        data = new { result = false };
        //    result.Data = data;
        //    return result;
        //}

        //[CompressFilter]
        //public JsonResult tblContentGetBlogZone()
        //{
        //    JsonResult result = new JsonResult();
        //    result.JsonRequestBehavior = JsonRequestBehavior.AllowGet;

        //    var lst = from p in db.Api_tblContentGetBlogZone()
        //              select new { p.Id, p.ZoneId, p.Title, p.ViewCount, DistributionDate = ConvertUtility.ToDateTime(p.DistributionDate).ToString("dd/MM/yyyy HH:mm"), p.Avatar };
        //    object data = null;
        //    var lstTmp = lst.ToList();

        //    if (lstTmp.Count > 0)
        //        data = new { result = true, ListData = lstTmp };
        //    else
        //        data = new { result = false };
        //    result.Data = data;
        //    return result;
        //}

        [CompressFilter]
        public JsonResult tblContentGetByZoneAndCategory(int ZoneId, int CatId, int PageSize, int pageNumber)
        {
            JsonResult result = new JsonResult();
            result.JsonRequestBehavior = JsonRequestBehavior.AllowGet;

            List<ListContent> lst = new List<ListContent>();
            object obj = DistCache.Get(MemcachedKey.hstblContentGetByZoneAndCategory + ZoneId + "_" + CatId + "_" + "_" + pageNumber);
            if (obj == null)
            {
                if (ZoneId == 3)
                {
                    lst = clsFunction.Api_tblContentEnterGetByZoneAndCategory(ZoneId, CatId, PageSize, pageNumber);
                }
                else
                {
                    lst = clsFunction.Api_tblContentGetByZoneAndCategory(ZoneId, CatId, PageSize, pageNumber);
                }
                DistCache.Add(MemcachedKey.hstblContentGetByZoneAndCategory + ZoneId + "_" + CatId + "_" + "_" + pageNumber, lst);
            }
            else
            {
                lst = (List<ListContent>)obj;
            }

            object data = null;
            var lstTmp = lst.ToList();

            if (lstTmp.Count > 0)
                data = new { result = true, ListData = lstTmp };
            else
                data = new { result = false };
            result.Data = data;
            return result;
        }

        [CompressFilter]
        public JsonResult ContentSearchKeyword(string pKeyword, int PageSize, int pageNumber)
        {
            JsonResult result = new JsonResult();
            result.JsonRequestBehavior = JsonRequestBehavior.AllowGet;

            List<ListContent> lst = new List<ListContent>();
            object obj = DistCache.Get(MemcachedKey.hstblContentSearchKeyword + pKeyword + "_" + "_" + pageNumber);
            if (obj == null)
            {
                lst = clsFunction.Api_tblContentSearchKeyword(pKeyword, PageSize, pageNumber);
                DistCache.Add(MemcachedKey.hstblContentSearchKeyword + pKeyword + "_" + "_" + pageNumber, lst);
            }
            else
            {
                lst = (List<ListContent>)obj;
            }

            object data = null;
            var lstTmp = lst.ToList();

            if (lstTmp.Count > 0)
                data = new { result = true, ListData = lstTmp };
            else
                data = new { result = false };
            result.Data = data;
            return result;
        }

        //[CompressFilter]
        //public JsonResult GetListSubCategory(int id)
        //{
        //    JsonResult result = new JsonResult();
        //    result.JsonRequestBehavior = JsonRequestBehavior.AllowGet;
        //    var lst = from p in db.tblSubCategories
        //              where p.IdCategory == id
        //              select new { p.Id, p.Title };
        //    object data = null;
        //    data = new { result = true, ListData = lst };
        //    result.Data = data;
        //    return result;
        //}

        //[CompressFilter]
        //public JsonResult GetInfo(int id)
        //{
        //    JsonResult result = new JsonResult();
        //    result.JsonRequestBehavior = JsonRequestBehavior.AllowGet;
        //    ContentInfo info = new ContentInfo();
        //    object obj = DistCache.Get(MemcachedKey.hsGetInfo + id);
        //    if (obj == null)
        //    {
        //        info = clsFunction.GetInfo(id);
        //        DistCache.Add(MemcachedKey.hsGetInfo + id, info);
        //    }
        //    else
        //    {
        //        info = (ContentInfo)obj;
        //    }

        //    object data = null;
        //    data = new { result = true, Info = info };
        //    result.Data = data;
        //    return result;
        //}

        [CompressFilter]
        public JsonResult GetInfo(int id)
        {
            string lOld = "src=\"//www.youtube.com";
            string lNew = "src=\"http://www.youtube.com";

            JsonResult result = new JsonResult();
            result.JsonRequestBehavior = JsonRequestBehavior.AllowGet;

            object obj = DistCache.Get(MemcachedKey.hsGetInfo + id.ToString());
            if (obj == null)
            {
                var lst = from p in db.Api_tblContent_GetInfo(id)
                      where p.Id == id
                          select new { p.Id, p.ZoneId, p.Title, p.Teaser, p.Avatar, p.TagDisplay, p.ViewCount, Body = p.Boby.Replace(lOld, lNew).Replace("src=\"/embed", "title=\"/embed"), DistributionDate = ConvertUtility.ToDateTime(p.DistributionDate).ToString("dd/MM/yyyy HH:mm"), p.Source, strLink = "http://yan.vn/" + StringUtility.UnicodeToKoDau(p.Title) + "-" + p.Id + ".html" };
                DistCache.Add(MemcachedKey.hsGetInfo + id.ToString(), lst);

                object data = null;
                data = new { result = true, Info = lst };
                result.Data = data;
            }
            else
            {
                object data = null;
                data = new { result = true, Info = obj };
                result.Data = data;
            }
            return result;
        }

        //[CompressFilter]
        //public JsonResult GetListNewVideo(int? intStart, int? intOffset)
        //{
        //    JsonResult result = new JsonResult();
        //    result.JsonRequestBehavior = JsonRequestBehavior.AllowGet;

        //    if (intStart == null)
        //        intStart = 1;

        //    if (intOffset == null)
        //        intOffset = 10;

        //    int? intCount = 0;

        //    var lst = from p in db.tblContentAPIGetListNewVideo(intStart, intOffset, ref intCount)
        //              select new { p.Id, p.Title, p.Avatar, DistributionDate = ConvertUtility.ToDateTime(p.DistributionDate).ToString("dd/MM/yyyy HH:mm") };

        //    object data = null;
        //    var lstTmp = lst.ToList();

        //    if (lstTmp.Count > 0)
        //        data = new { result = true, ListData = lstTmp, Total = intCount };
        //    else
        //        data = new { result = false };

        //    result.Data = data;
        //    return result;
        //}

        //[CompressFilter]
        //public JsonResult GetListRecentVideo(int? intStart, int? intOffset)
        //{
        //    JsonResult result = new JsonResult();
        //    result.JsonRequestBehavior = JsonRequestBehavior.AllowGet;

        //    if (intStart == null)
        //        intStart = 1;

        //    if (intOffset == null)
        //        intOffset = 10;

        //    int? intCount = 0;

        //    var lst = from p in db.tblContentAPIGetListRecentVideo(intStart, intOffset, ref intCount)
        //              select new { p.Id, p.Title, p.Avatar, DistributionDate = ConvertUtility.ToDateTime(p.DistributionDate).ToString("dd/MM/yyyy HH:mm") };

        //    object data = null;
        //    var lstTmp = lst.ToList();

        //    if (lstTmp.Count > 0)
        //        data = new { result = true, ListData = lstTmp, Total = intCount };
        //    else
        //        data = new { result = false };

        //    result.Data = data;
        //    return result;
        //}

        //[CompressFilter]
        //public JsonResult GetListVideoByCatId(int Id, int? intStart, int? intOffset)
        //{
        //    JsonResult result = new JsonResult();
        //    result.JsonRequestBehavior = JsonRequestBehavior.AllowGet;

        //    if (intStart == null)
        //        intStart = 1;

        //    if (intOffset == null)
        //        intOffset = 10;

        //    int? intCount = 0;

        //    var lst = from p in db.tblContentAPIGetListByCatId(Id, intStart, intOffset, ref intCount)
        //              select new { p.Id, p.Title, p.Avatar, DistributionDate = ConvertUtility.ToDateTime(p.DistributionDate).ToString("dd/MM/yyyy HH:mm") };

        //    object data = null;
        //    var lstTmp = lst.ToList();

        //    if (lstTmp.Count > 0)
        //        data = new { result = true, ListData = lstTmp, Total = intCount };
        //    else
        //        data = new { result = false };

        //    result.Data = data;
        //    return result;
        //}

        //[CompressFilter]
        //public JsonResult GetInfoVideo(int id)
        //{
        //    JsonResult result = new JsonResult();
        //    result.JsonRequestBehavior = JsonRequestBehavior.AllowGet;
        //    ContentInfo info = new ContentInfo();
        //    object obj = DistCache.Get(MemcachedKey.hsGetInfoVideo + id);
        //    if (obj == null)
        //    {
        //        info = clsFunction.GetInfoVideo(id);
        //        DistCache.Add(MemcachedKey.hsGetInfoVideo + id, info);
        //    }
        //    else
        //    {
        //        info = (ContentInfo)obj;
        //    }

        //    object data = null;

        //    data = new { result = true, Info = info };

        //    result.Data = data;
        //    return result;
        //}

        [CompressFilter]
        public JsonResult GetInfoVideo(int id)
        {
            JsonResult result = new JsonResult();
            result.JsonRequestBehavior = JsonRequestBehavior.AllowGet;

            ContentInfo retVal = clsFunction.GetInfoVideo(id);
            if (retVal.Folder >= 201403)
            {
                string strName = retVal.VideoName.ToLower().Replace(".mp4", "");
                retVal.urlVideo = retVal.HttpAddress + "YanVideo/" + retVal.Folder + "/" + strName + "/" + strName + ".m3u8";
            }
            else
            {
                retVal.urlVideo = retVal.HttpAddress + "YanVideo/" + retVal.Folder + "/" + retVal.VideoName;
            }

            var lst = from p in db.Api_tblContentAPIGetInfoVideo(id)
                      select new { p.Id, p.Title, p.Teaser, p.Boby, p.Avatar, p.TagDisplay, DistributionDate = ConvertUtility.ToDateTime(p.DistributionDate).ToString("dd/MM/yyyy HH:mm"), urlVideo = retVal.urlVideo, p.ViewCount, p.Source, strLink = "http://yan.vn/" + StringUtility.UnicodeToKoDau(p.Title) + "-v-" + p.Id + ".html" };

            object data = null;

            data = new { result = true, Info = lst };

            result.Data = data;
            return result;
        }


        //[CompressFilter]
        //public JsonResult GetListHotNews(int? intStart, int? intOffset)
        //{
        //    JsonResult result = new JsonResult();
        //    result.JsonRequestBehavior = JsonRequestBehavior.AllowGet;

        //    if (intStart == null)
        //        intStart = 1;

        //    if (intOffset == null)
        //        intOffset = 10;

        //    int? intCount = 0;

        //    var lst = from p in db.tblContentAPIGetListHotNews(intStart, intOffset, ref intCount)
        //              select new { p.Id, p.Title, p.Avatar, DistributionDate = ConvertUtility.ToDateTime(p.DistributionDate).ToString("dd/MM/yyyy HH:mm") };

        //    object data = null;
        //    var lstTmp = lst.ToList();

        //    if (lstTmp.Count > 0)
        //        data = new { result = true, ListData = lstTmp, Total = intCount };
        //    else
        //        data = new { result = false };

        //    result.Data = data;
        //    return result;
        //}

        //[CompressFilter]
        //public JsonResult SearchVideoNews(string strText, int? intStart, int? intOffset)
        //{
        //    JsonResult result = new JsonResult();
        //    result.JsonRequestBehavior = JsonRequestBehavior.AllowGet;

        //    if (intStart == null)
        //        intStart = 1;

        //    if (intOffset == null)
        //        intOffset = 10;

        //    int? intCount = 0;

        //    var lst = from p in db.tblContentAPISearchVideoNews(strText, intStart, intOffset, ref intCount)
        //              select new { p.Id, p.Title, p.Avatar, DistributionDate = ConvertUtility.ToDateTime(p.DistributionDate).ToString("dd/MM/yyyy HH:mm") };

        //    object data = null;
        //    var lstTmp = lst.ToList();

        //    if (lstTmp.Count > 0)
        //        data = new { result = true, ListData = lstTmp, Total = intCount };
        //    else
        //        data = new { result = false };

        //    result.Data = data;
        //    return result;
        //}


        public ActionResult FacebookComments(string url)
        {
            ViewData["strUrl"] = url;
            return View();
        }
    }
}
